package com.aispeech.jarpc.op.post;

public class PostEnv {
    private static final String JSON_TEMPLATE = "{\\\"" +
            "punctuation\\\":{\\\"use_period_split\\\":%d}," +
            "\\\"smooth\\\":{\\\"use_txt_smooth\\\":%d}," +
            "\\\"smooth_punc_unite\\\":{\\\"switch_on\\\":%d,\\\"use_period_split\\\":%d,\\\"use_txt_smooth\\\":%d}," +
            "\\\"ITN\\\":{\\\"use_inverse_txt\\\":%d}," +
            "\\\"sensitive\\\":{\\\"mgc_bin_path\\\":\\\"%s\\\"}," +
            "\\\"hotword\\\":{\\\"hotword_file_path\\\":\\\"%s\\\"}," +
            "\\\"POS\\\":{\\\"switch_on\\\":%d,\\\"wp_in_merge\\\":%d}," +
            "\\\"paragraph\\\":{\\\"switch_on\\\":%d}," +
            "\\\"pinyin\\\":{\\\"switch_on\\\":%d,\\\"use_tone\\\":%d}" +
            "}";

    private int useFullstop = 0;
    private int useTxtSmooth = 0;
    private int useITN = 0;
    private int usePOS = 0;
    private int wpInOnebest = 0;
    private int useParagraph = 0;
    private int usePinyin = 0;
    private int useTone = 0;
    private int switchOn = 1;
    private String sensitiveBinPath;
    private String hotwordFilePath;

    public PostEnv(boolean useFullstop, boolean useTxtSmooth, boolean useITN, boolean usePOS,
                   String sensitiveBinPath, String hotwordFilePath) {
        this(useFullstop, useTxtSmooth, useITN, usePOS, false, false, false, sensitiveBinPath, hotwordFilePath, true);
    }

    public PostEnv(boolean useFullstop, boolean useTxtSmooth, boolean useITN, boolean usePOS,
                   String sensitiveBinPath, String hotwordFilePath, boolean switchOn) {
        this(useFullstop, useTxtSmooth, useITN, usePOS, false, false, false, sensitiveBinPath, hotwordFilePath, switchOn);
    }

    public PostEnv(boolean useFullstop, boolean useTxtSmooth, boolean useITN, boolean usePOS, boolean useParagraph, boolean usePinyin, boolean useTone,
                   String sensitiveBinPath, String hotwordFilePath, boolean switchOn) {
        this.useFullstop = useFullstop ? 1 : 0;
        this.useTxtSmooth = useTxtSmooth ? 1 : 0;
        this.useITN = useITN ? 1 : 0;
        this.usePOS = usePOS ? 1 : 0;
        this.useParagraph = useParagraph ? 1 : 0;
        this.usePinyin = usePinyin ? 1 : 0;
        this.switchOn = switchOn ? 1 : 0;

        if (useTone) {
            this.usePinyin = 1;
            this.useTone = 1;
        } else {
            this.useTone = 0;
        }

        this.sensitiveBinPath = (sensitiveBinPath == null || sensitiveBinPath.isEmpty()) ? "0" : sensitiveBinPath;
        this.hotwordFilePath = (hotwordFilePath == null || hotwordFilePath.isEmpty()) ? "0" : hotwordFilePath;
    }

    public PostEnv(boolean useFullstop, boolean useTxtSmooth, boolean useITN, boolean usePOS, boolean wpInOnebest, boolean useParagraph, boolean usePinyin, boolean useTone,
                   String sensitiveBinPath, String hotwordFilePath) {
        this.useFullstop = useFullstop ? 1 : 0;
        this.useTxtSmooth = useTxtSmooth ? 1 : 0;
        this.useITN = useITN ? 1 : 0;
        this.usePOS = usePOS ? 1 : 0;
        this.wpInOnebest = wpInOnebest ? 1 : 0;
        this.useParagraph = useParagraph ? 1 : 0;
        this.usePinyin = usePinyin ? 1 : 0;

        if (useTone) {
            this.usePinyin = 1;
            this.useTone = 1;
        } else {
            this.useTone = 0;
        }

        this.sensitiveBinPath = (sensitiveBinPath == null || sensitiveBinPath.isEmpty()) ? "0" : sensitiveBinPath;
        this.hotwordFilePath = (hotwordFilePath == null || hotwordFilePath.isEmpty()) ? "0" : hotwordFilePath;
    }

    @Override
    public String toString() {
        return String.format(
                JSON_TEMPLATE,
                useFullstop,
                useTxtSmooth,
                switchOn,
                useFullstop,
                useTxtSmooth,
                useITN,
                sensitiveBinPath,
                hotwordFilePath,
                usePOS,
                wpInOnebest,
                useParagraph,
                usePinyin,
                useTone
        );
    }
}
